Blockly.FieldDropdown.CreateAsync = function(menuFunc) {
    var dropdown = new Blockly.FieldDropdown(function(){
        return [
            ["", null]
        ]
    }, function(){
        return null
    })
    dropdown.isAsync = true
    dropdown.asyncMenuFunc = menuFunc
    return dropdown ;
}

Blockly.FieldDropdown.prototype.oriShowEditor_ = Blockly.FieldDropdown.prototype.showEditor_
Blockly.FieldDropdown.prototype.showEditor_ = async function() {
    if(!this.isAsync) 
        return this.oriShowEditor_()

    Blockly.WidgetDiv.show(this, this.sourceBlock_.RTL, null);
    var menu = await this.createMenu_();
    console.log(this)
    this.addActionListener_(menu);
    this.positionMenu_(menu);
}

Blockly.FieldDropdown.prototype.oriCreateMenu_ = Blockly.FieldDropdown.prototype.createMenu_
Blockly.FieldDropdown.prototype.createMenu_ = async function() {
    if(!this.isAsync) 
        return this.oriCreateMenu_()

    var menu = new goog.ui.Menu();
    menu.setRightToLeft(this.sourceBlock_.RTL);

    var options = await this.asyncMenuFunc();

    for (var i = 0; i < options.length; i++) {
        var content = options[i][0]; // Human-readable text or image.
        var value = options[i][1];   // Language-neutral value.
        if (typeof content == 'object') {
        // An image, not text.
        var image = new Image(content['width'], content['height']);
        image.src = content['src'];
        image.alt = content['alt'] || '';
        content = image;
        }
        var menuItem = new goog.ui.MenuItem(content);
        menuItem.setRightToLeft(this.sourceBlock_.RTL);
        menuItem.setValue(value);
        menuItem.setCheckable(true);
        menu.addChild(menuItem, true);
        menuItem.setChecked(value == this.value_);
    }
    return menu;
};